package com.sgl.util;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 分页参数
 */
public class PageBean<E> implements Serializable{
	
	private static final long serialVersionUID = -2962815267157436206L;
	/**
	 * 本页的数据列表
	 */
	private List<E> content = new ArrayList<E>();
	/**
	 * 当前页码
	 */
	private int pageNo=1;  
	/**
	 * 每页显示多少条数据
	 */
	private int pageSize = 10;
	/**
	 * 总记录数
	 */
	private int totalCount;
	/**
	 * 总页数
	 */
	private int totalPage;
	/**
	 * 页码列表的开始索引（从1开始）
	 */
	private int beginPageIndex;

	/**
	 * 页码列表的结束索引
	 */
	private int endPageIndex;
	/**
	 * 排序列名
	 */
	private String sort;
	/**
	 * 排序方式   desc asc
	 */
	private String order;
	
	private int isLimit;
	
	private Map<String, Object> param = null;

	public PageBean() {
		
	}
	
	public PageBean(int iDisplayStart,int iDisplayLength,String sortCol,String sortType) {
		Integer pageNumber = (iDisplayStart / iDisplayLength) + 1;
		this.pageNo = pageNumber;
		this.pageSize = iDisplayLength;
		this.sort = sortCol;
		this.order = sortType;
	}
	
	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public String getOrder() {
		return order;
	}

	public void setOrder(String order) {
		this.order = order;
	}

	/**
	 * 获取mysql数据库开始索引(从0开始)
	 */
	public int getBeginIndex() {
		pageSize=pageSize>50?50:pageSize;

		return (pageNo-1)*pageSize;
	}

	public List<E> getContent() {
		return content;
	}

	public void setContent(List<E> content) {
		this.content = content;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getPageSize() {
		pageSize=pageSize>60?60:pageSize;
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getBeginPageIndex() {
		return beginPageIndex;
	}

	public void setBeginPageIndex(int beginPageIndex) {
		this.beginPageIndex = beginPageIndex;
	}

	public int getEndPageIndex() {
		return endPageIndex;
	}

	public void setEndPageIndex(int endPageIndex) {
		this.endPageIndex = endPageIndex;
	}

	public void setTotalCount(Integer totalCount) {
		if(totalCount==null)
			totalCount=0;
		totalPage = (totalCount + pageSize - 1) / pageSize;
		this.totalCount = totalCount;
	}
	
	public Map<String, Object> getParam() {
		return param;
	}
	
	public void setParam(Map<String, Object> param) {
		this.param = param;
	}

	public int getIsLimit() {
		return isLimit;
	}

	public void setIsLimit(int isLimit) {
		this.isLimit = isLimit;
	}
}
